home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1993 September / September 93.iso / Archives / Utilities / Disk & File / Disk / Icons / Icon Disposer / IconDisposerCDEV.c < prev    next >
Text File  |  1993-06-16  |  8KB  |  333 lines

  1. #define    SystemSevenOrLater    1
  2.  
  3. #include <Quickdraw.h>
  4. #include <Files.h>
  5. #include <Memory.h>
  6. #include <OSUtils.h>
  7. #include <TextEdit.h>
  8. #include <Devices.h>
  9. #include <Dialogs.h>
  10. #include <Packages.h>
  11. #include <GestaltEqu.h>
  12. #include <Resources.h>
  13. #include <Controls.h>
  14.  
  15. #define    kOnMask            (0x01)
  16. #define    kOnClear        (0xFF - kOnMask)
  17. #define    kCDMask            (0x02)
  18. #define    kCDClear        (0xFF - kCDMask)
  19. #define    kNetVolMask        (0x04)
  20. #define    kNetVolClear    (0xFF - kNetVolMask)
  21. #define    kFloppyMask        (0x08)
  22. #define    kFloppyClear    (0xFF - kFloppyMask)
  23. #define    kLocalMask        (0x10)
  24. #define    kLocalClear        (0xFF - kLocalMask)
  25.  
  26. #define    kOnRadio        2
  27. #define    kOffRadio        3
  28.  
  29. #define    kCDCheck        5
  30. #define    kNetVolCheck    6
  31. #define    kFloppyCheck    7
  32. #define    kLocalCheck        8
  33.  
  34. #define    kCheckFrameItem    9
  35. #define    kStatusItem        10
  36. #define    kStatFrameItem    11
  37.  
  38. struct GlobalVar {
  39. unsigned char    flags;
  40.     short        volumes[50];
  41. };
  42.  
  43. typedef    struct GlobalVar GlobalVar;
  44. typedef    GlobalVar *GlobalVarPtr;
  45. typedef    GlobalVar **GlobalVarHandle;
  46.  
  47. void ReevaluateVolumes(GlobalVarHandle globals);
  48.  
  49. pascal long IconDisposerCDEV(short message, short item, short numItems, 
  50.         short CPanelID, EventRecord    *theEvent, Handle cdevStorage, 
  51.         DialogPtr CPDialog)
  52.     {
  53. #pragma unused (CPanelID)
  54.  
  55.     GlobalVar        **globals = nil;
  56.  
  57.     ControlHandle    onButton;
  58.     ControlHandle    offButton;
  59.     ControlHandle    aControlHandle;
  60.     ControlHandle    cdHandle;
  61.     ControlHandle    netVolHandle;
  62.     ControlHandle    floppyHandle;
  63.     ControlHandle    localHandle;
  64.     ControlHandle    statusHandle;
  65.     short            type;
  66.     OSErr            theErr = noErr;
  67.     Rect            rect;
  68.     Handle            aHandle;
  69.     short            itemHit = item - numItems;
  70.     short            partID;
  71.     short            initControlValue;
  72.     short            value;
  73. unsigned char        maskVal = 0;
  74. unsigned char        clearVal = 0;
  75. unsigned char        maskValue = 0;
  76. unsigned char        flagCopy = 0;
  77.  
  78.     if (message == macDev)
  79.         return(1);
  80.     else 
  81.         if (cdevStorage)
  82.             {
  83.             GetDItem(CPDialog, kOnRadio, &type, (Handle *) &onButton, &rect);
  84.             GetDItem(CPDialog, kOffRadio, &type, (Handle *) &offButton, &rect);
  85.             GetDItem(CPDialog, kCDCheck, &type, (Handle *) &cdHandle, &rect);
  86.             GetDItem(CPDialog, kNetVolCheck, &type, (Handle *) &netVolHandle, &rect);
  87.             GetDItem(CPDialog, kFloppyCheck, &type, (Handle *) &floppyHandle, &rect);
  88.             GetDItem(CPDialog, kLocalCheck, &type, (Handle *) &localHandle, &rect);
  89.             GetDItem(CPDialog, kStatusItem, &type, (Handle *) &statusHandle, &rect);
  90.                 
  91.             theErr = Gestalt('byeb', (long *) &globals);
  92.  
  93.             if (theErr == gestaltUnknownErr)
  94.                 return(cdevGenErr);
  95.  
  96.             if (theErr == gestaltUndefSelectorErr)
  97.                 {
  98.                 globals = nil;
  99.                 aHandle = Get1IndResource('glob', 1);
  100.  
  101.                 if (aHandle)
  102.                     {
  103.                     flagCopy = *(unsigned char *)(*aHandle);
  104.                     ReleaseResource(aHandle);
  105.                     }
  106.                 else
  107.                     flagCopy = 0;
  108.                 }
  109.             else
  110.                 flagCopy = (*globals)->flags;
  111.  
  112.             switch (message) {
  113.                 case initDev:
  114.                     if (kOnMask & flagCopy)
  115.                         {
  116.                         SetCtlValue(onButton, 1);
  117.                         SetCtlValue(offButton, 0);
  118.                         initControlValue = 0;
  119.                         }
  120.                     else
  121.                         {
  122.                         SetCtlValue(onButton, 0);
  123.                         SetCtlValue(offButton, 1);
  124.                         initControlValue = 255;
  125.                         }
  126.  
  127.                     HiliteControl(cdHandle, initControlValue);
  128.                     HiliteControl(netVolHandle, initControlValue);
  129.                     HiliteControl(floppyHandle, initControlValue);
  130.                     HiliteControl(localHandle, initControlValue);
  131.  
  132.                     if (kCDMask & flagCopy)
  133.                         SetCtlValue(cdHandle, 1);
  134.                     else
  135.                         SetCtlValue(cdHandle, 0);
  136.                         
  137.                     if (kNetVolMask & flagCopy)
  138.                         SetCtlValue(netVolHandle, 1);
  139.                     else
  140.                         SetCtlValue(netVolHandle, 0);
  141.  
  142.                     if (kFloppyMask & flagCopy)
  143.                         SetCtlValue(floppyHandle, 1);
  144.                     else
  145.                         SetCtlValue(floppyHandle, 0);
  146.  
  147.                     if (kLocalMask & flagCopy)
  148.                         SetCtlValue(localHandle, 1);
  149.                     else
  150.                         SetCtlValue(localHandle, 0);
  151.  
  152.                     break;
  153.  
  154.                 case closeDev:
  155.                     if (!globals)
  156.                         {
  157.                         flagCopy = 0;
  158.  
  159.                         value = GetCtlValue(onButton);
  160.                         if (value)
  161.                             flagCopy |= kOnMask;
  162.                         else
  163.                             flagCopy &= kOnClear;
  164.  
  165.                         value = GetCtlValue(cdHandle);
  166.                         if (value)
  167.                             flagCopy |= kCDMask;
  168.                         else
  169.                             flagCopy &= kCDClear;
  170.  
  171.                         value = GetCtlValue(netVolHandle);
  172.                         if (value)
  173.                             flagCopy |= kNetVolMask;
  174.                         else
  175.                             flagCopy &= kNetVolClear;
  176.  
  177.                         value = GetCtlValue(floppyHandle);
  178.                         if (value)
  179.                             flagCopy |= kFloppyMask;
  180.                         else
  181.                             flagCopy &= kFloppyClear;
  182.  
  183.                         value = GetCtlValue(localHandle);
  184.                         if (value)
  185.                             flagCopy |= kLocalMask;
  186.                         else
  187.                             flagCopy &= kLocalClear;
  188.                         }
  189.  
  190.                     aHandle = (Handle) Get1IndResource('glob', 1);
  191.  
  192.                     if (aHandle)
  193.                         {
  194.                         RmveResource(aHandle);
  195.                         DisposeHandle((Handle) aHandle);
  196.                         }
  197.  
  198.                     aHandle = NewHandle(1);
  199.                     if (aHandle)
  200.                         {
  201.                         *(unsigned char *)(*aHandle) = flagCopy;
  202.                         AddResource(aHandle, 'glob', 1, "\p");
  203.                         ChangedResource(aHandle);
  204.                         if (ResError())
  205.                             break;
  206.                         WriteResource(aHandle);
  207.                         ReleaseResource(aHandle);
  208.                         }
  209.                     
  210.                     if (globals)
  211.                         ReevaluateVolumes(globals);
  212.                     break;
  213.     
  214.                 case hitDev:
  215.                     GlobalToLocal(&theEvent->where);
  216.                     partID = FindControl(theEvent->where, (WindowPtr) CPDialog, &aControlHandle);
  217.  
  218.                     switch (itemHit) {
  219.                         case kOnRadio:
  220.                             if (!(kOnMask & flagCopy))
  221.                                 {
  222.                                 SetCtlValue(offButton, 0);
  223.                                 if (globals)
  224.                                     (*globals)->flags |= kOnMask;
  225.                                 }
  226.                             initControlValue = 0;
  227.  
  228.                         case kOffRadio:
  229.                             if (itemHit == kOffRadio)
  230.                                 {
  231.                                 if (kOnMask & flagCopy)
  232.                                     {
  233.                                     SetCtlValue(onButton, 0);
  234.                                     if (globals)
  235.                                         (*globals)->flags &= kOnClear;
  236.                                     }
  237.                                 initControlValue = 255;
  238.                                 }
  239.  
  240.                             SetCtlValue(aControlHandle, 1);
  241.                             HiliteControl(cdHandle, initControlValue);
  242.                             HiliteControl(netVolHandle, initControlValue);
  243.                             HiliteControl(floppyHandle, initControlValue);
  244.                             HiliteControl(localHandle, initControlValue);
  245.                             break;
  246.                         }
  247.  
  248.                     if (partID)
  249.                         partID = TrackControl(aControlHandle, theEvent->where, 
  250.                                 nil);
  251.  
  252.                     if (partID)
  253.                         {
  254.                         switch (itemHit) {
  255.                             case kCDCheck:
  256.                                 maskVal = kCDMask;
  257.                                 clearVal = kCDClear;
  258.                                 break;
  259.                             case kNetVolCheck:
  260.                                 maskVal = kNetVolMask;
  261.                                 clearVal = kNetVolClear;
  262.                                 break;
  263.                             case kFloppyCheck:
  264.                                 maskVal = kFloppyMask;
  265.                                 clearVal = kFloppyClear;
  266.                                 break;
  267.                             case kLocalCheck:
  268.                                 maskVal = kLocalMask;
  269.                                 clearVal = kLocalClear;
  270.                                 break;
  271.                             }
  272.  
  273.                         if (maskVal & flagCopy)
  274.                             {
  275.                             SetCtlValue(aControlHandle, 0);
  276.                             if (globals)
  277.                                 (*globals)->flags &= clearVal;
  278.                             }
  279.                         else
  280.                             {
  281.                             SetCtlValue(aControlHandle, 1);
  282.                             if (globals)
  283.                                 (*globals)->flags |= maskVal;
  284.                             }
  285.                         }
  286.                     break;
  287.                 case updateDev:
  288.                 case activDev:
  289.                     DrawControls((WindowPtr) CPDialog);
  290.                     GetDItem(CPDialog, kStatFrameItem, &type, 
  291.                         (Handle *) &aControlHandle, &rect);
  292.                     FrameRect(&rect);
  293.                     if (globals == nil)
  294.                         SetIText((Handle) statusHandle, 
  295.                             "\pThis Control Panel was not installed. Please reboot.");
  296.                     GetDItem(CPDialog, kCheckFrameItem, &type, 
  297.                         (Handle *) &aControlHandle, &rect);
  298.                     FrameRect(&rect);
  299.                     break;
  300.                 }
  301.     
  302.             return ((long) cdevStorage);
  303.             }
  304.     return (0);
  305.     }
  306.  
  307. void ReevaluateVolumes(GlobalVarHandle globals)
  308.     {
  309.     VCB*        vcbQueue = *((QHdrPtr *) 0x0358);
  310.     short        vRefNum;
  311.     short        newValue;
  312.  
  313.     Debugger();
  314.  
  315.     while (vcbQueue)
  316.         {
  317.         vRefNum = vcbQueue->vcbVRefNum;
  318.  
  319.         if (((vcbQueue->vcbFSID > 0) && (kNetVolMask & (*globals)->flags)) ||
  320.             (((vcbQueue->vcbDrvNum == 1) || (vcbQueue->vcbDrvNum == 2)) &&
  321.             ((*globals)->flags & kFloppyMask)) || 
  322.             ((vcbQueue->vcbAtrb & 0x80) && ((*globals)->flags & kCDMask)) ||
  323.             ((*globals)->flags & kLocalMask))
  324.             newValue = 1;
  325.         else
  326.             newValue = 0;
  327.         
  328.         *(short *)((*(Ptr *)globals) + (-vRefNum)) = newValue;
  329.  
  330.         vcbQueue =(VCB *) vcbQueue->qLink;
  331.         }
  332.     }
  333.